<template>
  <div>
    <el-divider content-position="left">审核记录流转</el-divider>
    <div class="total-tips">共有 {{ recordTotal }} 条记录, 目前至多展示最新 {{ maxCount }} 条</div>
    <el-table :data="recordList" stripe border>
      <!-- <el-table-column label="前置状态" width="100">
        <template slot-scope="scope">
          <span>
            {{
              dict.dict['supplier_status'][scope.row.oldStatus] &&
              dict.dict['supplier_status'][scope.row.oldStatus].label
            }}
          </span>
        </template>
      </el-table-column> -->
      <el-table-column label="审核状态" width="100">
        <template slot-scope="scope">
          <span>
            {{ dict.label.supplier_status[scope.row.status] }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="reason" label="操作理由"></el-table-column>
      <el-table-column prop="createTime" label="操作时间" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createBy" label="操作人" width="150" v-if="!hideOp"></el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { parseTime } from '@/utils/index';

  export default {
    props: {
      records: {
        type: Array,
        default: () => [],
      },
      hideOp: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        recordList: [],
        recordTotal: 0,
        maxCount: 5,
      };
    },
    watch: {
      records() {
        this.countRecord();
      },
    },
    mounted() {
      this.countRecord();
    },
    dicts: ['supplier_status'],
    methods: {
      parseTime,
      countRecord() {
        this.recordList = this.records
          .filter((record) => record.oldStatus == 'INIT')
          .slice(-1 * this.maxCount);

        this.recordTotal = this.records.length;
      },
    },
  };
</script>

<style lang="scss" scoped>
  .total-tips {
    padding-bottom: 5px;
    font-size: 12px;
  }
</style>
